version 7.0
log using interact3.log, replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*   File-Name:  interact3.do                                            *;
*   Date:       October 24, 2001                                        *;
*   Author:     MRG                                                     *;
*   Purpose:    Read eup dataset: Basic Model and interaction figures  *;
*   Input File: eup.dta                                                *;
*   Output File:Interact3.log                                           *;
*   Data Output:                                                        *;
*   Previous file:                                                      *;
*   Machine:    system11                                                *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set mem 10m;

use h:\ECSA\EUP\dofiles\eup.dta;

*     ****************************************************************  *;
*     Rename some of the variables to coincide more clearly with paper  *;
*     ****************************************************************  *;

rename bbdrlmag logmag_leftbbd ;
rename bbdrstfm  strongfm_leftbbd;
rename bbdrtarg targets_leftbbd;
rename ddebt1 lagdebt;
rename dbtserv2 debtcosts;
rename growth gdp;
rename pol1 govtype1;
rename pol2 govtype2;
rename pol3 govtype3;
rename partbbd2 leftbbd;
rename wkbpart leftwkb;
generate logmag_leftwkb = logmag*leftwkb;
generate strongfm_leftwkb = strongfm*leftwkb;
generate targets_leftwkb = targets*leftwkb;


*     ****************************************************************  *;
*       Specify model such as : y x j k l  xj xk xl jk jl kl            *;
*     ****************************************************************  *;

xtpcse  ddebt leftbbd logmag strongfm targets logmag_leftbbd 
        strongfm_leftbbd  targets_leftbbd lagdebt unemp  gdp debtcosts
        govtype1 govtype2 govtype3 austria belgium denmark finland 
        nether  spain sweden france germany greece  italy 
         if year>1980 & year<1993,p;

*     ****************************************************************  *;
*       The next line creates a variable to use as your modifying       *;
*       variable.  In calculations H stands for "hypothetical".         *;
*       _n   is a variable in data set that is equal to the observation *;
*       number.  We use it and some formula to create a variable that   *;
*       runs from the min to the max of the modifying variable.  So     *;
*       this has to be changed everytime the program is adapted to a    *;
*       new modifying variable.  NOTE: SINCE THE PROGRAM CREATES ALL    *;
*       KINDS OF TEMPORARY VARIABLES, YOU DON'T WANT TO SAVE YOUR DATA  *;
*       BASE AFTER RUNNING IT.  Also, before you run a similar program, *;
*       you'll want to clear the data from memory and load a fresh data *;
*       set.                                                            *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*                                   x2=JH                               *;
*     ****************************************************************  *;

generate JH=_n/10;    

replace JH=. if _n>50;

*     ****************************************************************  *;
*       The next lines create  constants of the value of 4              *;
*       representative values of the second and third qualitative       *;
*       modifying variable ()                                           *;
*     ****************************************************************  *;

generate k1=1;
generate k0=0;
generate l1=1;
generate l0=0;

*     ****************************************************************  *;
*      The next line creates a string variable called txt which is      *;
*      equal to the asterisk - this comes in handy when it's time to    *;
*      graph significant coefficients.                                  *;
*     ****************************************************************  *;

generate str1 txt="*";

*     ****************************************************************  *;
*      The stuff below  just renames some of the matrices and scalars   *;
*      in an intuitive manner.                                          *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];

scalar varb1=V[1,1];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar covb1b5=V[1,5];
scalar covb1b6=V[1,6];
scalar covb1b7=V[1,7];

set more off;

*     ****************************************************************  *;
*       The next line just lists the stuff we use to calculate          *;
*       conditional coefficients and standard errors.  These can be     *;
*       seen in the log file.                                           *;
*     ****************************************************************  *;

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb5 varb6 varb7 covb1b5 covb1b6 covb1b7; 

*     ****************************************************************  *;
*       Except for in left hand side of following, do search and        *;
*       replace for lmiH below //                                       *;
*     ****************************************************************  *;

gen conbk0l0= b1+b5*JH  if _n<51;
gen conbk1l0= b1+b5*JH+b6 if _n<51;
gen conbk0l1= b1+b5*JH+b7 if _n<51;
gen conbk1l1= b1+b5*JH+b6+b7 if _n<51;
    
set more off;

list conbk0l0 conbk1l0 conbk0l1 conbk1l1 in 1/50;

*     ****************************************************************  *;
*       These create conditional coefficients for b1 at lmiH, kH# //    *;
*     ****************************************************************  *;

gen consk0l0=sqrt(abs(varb1+varb5*JH^2+2*covb1b5*JH)) if _n<51;
gen consk1l0 =sqrt(abs(varb1+varb5*JH^2+2*covb1b5*JH+varb6+2*covb1b6)) if _n<51;
gen consk0l1=sqrt(abs(varb1+varb5*JH^2+2*covb1b5*JH+ varb7+2*covb1b7)) if _n<51;
gen consk1l1=sqrt(abs(varb1+varb5*JH^2+2*covb1b5*JH+varb6+2*covb1b6+ varb7+2*covb1b7)) if _n<51;

set more off;

list consk0l0 consk1l0 consk0l1 consk1l1 in 1/50;

gen contk0l0= conbk0l0/consk0l0;
gen contk1l0= conbk1l0/consk1l0;
gen contk0l1= conbk0l1/consk0l1;
gen contk1l1= conbk1l1/consk1l1;

list contk0l0  contk1l0 contk0l1 contk1l1 in 1/50;

*     ****************************************************************  *;
*       This creates a conditional t for each level of lmiHHH given     *;
*       which kH is chosen//                                            *;
*     ****************************************************************  *;

gen cobsk0l0 = conbk0l0;
gen cobsk1l0 = conbk1l0;
gen cobsk0l1 = conbk0l1;
gen cobsk1l1 = conbk1l1;

*     ****************************************************************  *;
*      These create "shadow" (thus the "S") variables for each of the   *;
*      conditional b's                                                  *;  
*     ****************************************************************  *;

replace cobsk0l0 = . if abs(contk0l0)<1.96;
replace cobsk1l0 = . if abs(contk1l0)<1.96;
replace cobsk0l1 = . if abs(contk0l1)<1.96;
replace cobsk1l1 = . if abs(contk1l1)<1.96;

list cobsk0l0  cobsk1l0 cobsk0l1 cobsk1l1 in 1/50;

*     ****************************************************************  *;
*       This creates missing values for all the insignificant shadow    *;
*       b's.  //                                                        *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       We do not want to graph the situation where there are both      *;
*       strong finance minister and targets since this never happens.   *;
*       This means ignoring the situations when k=1 AND l=1.            *;
*     ****************************************************************  *;


set textsize 100;

graph  conbk0l0  conbk1l0 conbk0l1  cobsk0l0  cobsk1l0 cobsk0l1 
          JH, psize(100) ylab xlab(1 2 3 4 5) pen(963333) 
        symbol(...[txt][txt][txt][txt]) c(llll....)sort  
        t1(Change in Gross Debt) b2(" ");

set textsize 100;

log close;
